package com.gui.windows.components;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//import java.io.File;

import com.design.DesignManager;
//import com.gui.beans.*;
import com.gui.windows.*;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

/**
 * Singleton Class that manages the main window menu bar.
 * */
public class MenuBar extends JMenuBar implements UserActions {

	//**************************************************************************************************
	//	Constructor.
	//**************************************************************************************************

	private static final long serialVersionUID = 1L;
	
	private static MenuBar menuBar = null;

	public static MenuBar getMenuBar(MainWindow mw) {
		if (menuBar == null) {
			menuBar = new MenuBar();
		}
		return menuBar;
	}

	private MenuBar () {
		super();
		designManager = DesignManager.getDesignManager();
		createMenuBar();
	}

	//**************************************************************************************************
	//	Atributes.
	//**************************************************************************************************

	// main window menu items.
	private JMenu fileMenu; // the menus available in the menu bar.
	private JMenu editMenu;
	private JMenuItem newTemplate; // the menu item.
	private JMenuItem loadTemplate;
	private JMenuItem saveTemplate;
//	private JMenuItem templateTools;
	private JMenuItem copy;
	private JMenuItem paste;
	
	private static DesignManager designManager;

	//**************************************************************************************************
	//	Methods that exports this Class (Public Methods).
	//**************************************************************************************************

	//**************************************************************************************************
	//	Inner Methods. (Private Methods) 
	//**************************************************************************************************

	private void createMenuBar() {
		fileMenu = new JMenu("File");
		editMenu = new JMenu("Edit");
		createBarMenus();
		this.add(fileMenu);
		this.add(editMenu);
	}

	private void createBarMenus () {
		createMenusSubItems();
		// adding items to file drop down menu.
		fileMenu.add(newTemplate);
		fileMenu.add(loadTemplate);
		fileMenu.add(saveTemplate);
		// adding items to edit drop down menu.
		editMenu.add(copy);
		editMenu.add(paste);
		// setting events for file drop down menu items.
		newTemplate.addActionListener(new NewTemplateHandler());
		loadTemplate.addActionListener(new LoadTemplateHandler());
		saveTemplate.addActionListener(new SaveTemplateHandler());
	}

	private void createMenusSubItems () {
		newTemplate = new JMenuItem("New Template");
		loadTemplate = new JMenuItem("Load Template");
		saveTemplate = new JMenuItem("Save Template");
		copy = new JMenuItem("Copy");
		paste = new JMenuItem("Paste");
	}

	//**************************************************************************************************
	//* Components handler classes. 
	//**************************************************************************************************

	private class NewTemplateHandler implements ActionListener {
		public void actionPerformed (ActionEvent e) {
			designManager.createTemplate();
		}
	}

	/**

	 * Manage the action events of the load image entry that exist in the file drop down menu.

	 * */
	private class LoadTemplateHandler implements ActionListener {
		public void actionPerformed (ActionEvent e) {
//			FileSelector fs = new XmlFileSelector(); // the templates are saved in XML files.
//			File file = fs.createAndShowGUI();
		}
	}

	private class SaveTemplateHandler implements ActionListener {
		public void actionPerformed (ActionEvent e) {
//			FileSelector fs = new XmlFileSelector();
//			File file = fs.createAndShowGUI();
		}
	}

}
